package com.chuangxin.data.chazidian;

import com.chuangxin.data.core.IDBasedFetcher;
import com.chuangxin.data.core.io.DataOutput;
import com.chuangxin.data.core.io.FileWriter;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.File;

/**
 * Created by Dawnwords on 2015/2/2.
 */
public class ZaoJuFetcher extends IDBasedFetcher {
    //    private static final int start = 1;
    private static final int start = 4857;
    private static final int end = 8854;
    private static final String template = "http://www.chazidian.com/zaoju${id}/";

    public ZaoJuFetcher(DataOutput dataOutput) {
        super(dataOutput, start, end, template);
    }

    protected TitleContent processDoc(Document doc, String url) {
        String title = doc.select("div.article_title > h1").eq(0).html();
        Elements wrapper = doc.select("div.article_detail");
        wrapper.select("p#pages").remove();
        wrapper.select("div.ad_660px").remove();
        String content = wrapper.html();
        return new TitleContent(title, content);
    }

    public static void main(String[] args) {
        new ZaoJuFetcher(new FileWriter("E:" + File.separator + "chazidian" + File.separator + "zaoju")).execute();
    }
}
